<!DOCTYPE html>
<html>

<head>
    <title locale="arozaudio/arozaudio-title">ArozOS Audio Test</title>
    <link rel="stylesheet" href="../../script/semantic/semantic.min.js">
    <script src="../../script/semantic/semantic.min.css"></script>
    <script src="../../script/jquery.min.js"></script>
    <script type="text/javascript" src="../../script/applocale.js"></script>
    <!--<script src="ao_module.js"></script> DOES NOT EXIST IN GOLANG VERSION-->
    <style>
        .flip {
            -moz-transform: scale(-1, 1);
            -webkit-transform: scale(-1, 1);
            -o-transform: scale(-1, 1);
            -ms-transform: scale(-1, 1);
            transform: scale(-1, 1);
        }
        
        .selectable {
            padding: 15px !important;
            border: 1px solid transparent;
            border-radius: 10px;
        }
        
        .selectable:hover {
            border: 1px solid #839ff5;
            background-color: #ccd9ff;
            cursor: pointer;
        }
    </style>
</head>

<body>
    <div class="ui container">
        <div class="ui basic segment">
            <div class="ui header">
                <span locale="arozaudio/system-audio">System Audio</span>
                <div class="sub header" locale="arozaudio/system-audio-subheader">Test and adjust your global audio / volume settings</div>
            </div>
        </div>
       
        <div class="ui grid">
            <div class="five wide column selectable" align="center" onClick="PlaySound('left');"><i class="volume up huge icon flip"></i><br><span locale="arozaudio/left-speaker">Left Speaker</span></div>
            <div class="six wide column selectable" align="center" onClick="PlaySound('both');"><i class="computer huge icon"></i><br><span locale="arozaudio/speaker-test">Speaker Test</span></div>
            <div class="five wide column selectable" align="center" onClick="PlaySound('right');"><i class="volume up huge icon"></i><br><span locale="arozaudio/right-speaker">Right Speaker</span></div>
        </div>
        <br>
        <div class="ui segment">
            <h5 locale="arozaudio/master-volume">Master Volume</h5>
            <div class="ui slider">
                <input id="gblvol" min="0" max="100" type="range" value="0" style="width: 100%;">
            </div>
            <p><span  locale="arozaudio/this-device-global-volume">This Device Global Volume: </span><span id="numdis">0%</span></p>
            <small style="font-size:80%;" locale="arozaudio/some-modules-volume">Some modules use stand-alone volume management system. Master volume may not be able to control all module's volume.</small>
        </div>
        <div style="display:none;">
            <audio id="both" controls><source src="../info/track/both.mp3" type="audio/mp3"></audio>
            <audio id="left" controls><source src="../info/track/left.mp3" type="audio/mp3"></audio>
            <audio id="right" controls><source src="../info/track/right.mp3" type="audio/mp3"></audio>
        </div>
    </div>
    <script>
        
        var audioTestLocale = NewAppLocale();
        audioTestLocale.init("../locale/system_settings/audio.json", function(){
            audioTestLocale.translate();
        });

        getGlobalVol();
        setInterval(getGlobalVol, 1000);

        function getGlobalVol() {
            var vol = localStorage.getItem("global_volume");
            if (vol == undefined || vol == "") {
                vol = 0;
                localStorage.setItem("global_volume", 0);
            }
            $("audio").prop("volume", parseFloat(vol));
            vol = parseFloat(vol) * 100; //Back to 0 - 100 scale
            vol = vol.toFixed(0);
            $("#gblvol").attr("value", vol);
            $("#numdis").html(vol + "%")

        }

        var b = document.getElementById("both");
        var l = document.getElementById("left");
        var r = document.getElementById("right");

        function PlaySound(keyword) {
            resetAllSoundTracks();
            if (keyword == "both") {
                b.play();
            } else if (keyword == "left") {
                l.play();
            } else {
                r.play();
            }
        }

        function resetAllSoundTracks() {
            b.pause();
            b.currentTime = 0;
            l.pause();
            l.currentTime = 0;
            r.pause();
            r.currentTime = 0;
        }

        $('input[type=range]').on('input', function() {
            $(this).trigger('change');
            var newval = ($(this).val());
            $("#numdis").html(newval + "%");
            newval = (newval / 100).toFixed(2);
            localStorage.setItem("global_volume", newval);
        });
    </script>
</body>

</html>
